﻿using FluentNHibernate.Mapping;
using Journal.Domain.Models;

namespace Journal.NHibernate.Mappings
{
    public class StudyGroupMap : ClassMap<StudyGroup>
    {
        public StudyGroupMap()
        {
            Id(x => x.Id).Not.Nullable().GeneratedBy.Identity();
            Map(x => x.Name).Length(50).Not.Nullable();
            References(x => x.User, "UserId").Cascade.None().Not.Nullable();
            References(x => x.EducationInstitution, "EducationInstitutionId").Cascade.None().Not.Nullable();
            References(x => x.StudyGroupInformation, "StudyGroupInformationId").Cascade.All().Not.Nullable();
            HasManyToMany(x => x.Students).Table("StudentToGroup").ParentKeyColumn("GroupId").ChildKeyColumn("UserId").Cascade.AllDeleteOrphan();
        } 
    }
}
